package com.web3.management.controller;

import com.web3.management.dto.ApiResponse;
import com.web3.management.dto.response.AccountTradeProgressResponse;
import com.web3.management.dto.response.OperationLogResponse;
import com.web3.management.dto.response.StatsOverviewResponse;
import com.web3.management.service.StatsService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import java.util.List;

/**
 * 统计控制器
 */
@RestController
@RequestMapping("/api/stats")
@RequiredArgsConstructor
@Validated
public class StatsController {

    private final StatsService statsService;

    @GetMapping("/overview")
    public ApiResponse<StatsOverviewResponse> getOverview() {
        return ApiResponse.success(statsService.getOverview());
    }

    @GetMapping("/recent-operations")
    public ApiResponse<List<OperationLogResponse>> getRecentOperations(
            @RequestParam(defaultValue = "10") @Min(1) @Max(100) Integer limit) {
        return ApiResponse.success(statsService.getRecentOperations(limit));
    }

    @GetMapping("/account-progress")
    public ApiResponse<List<AccountTradeProgressResponse>> getAccountProgress() {
        return ApiResponse.success(statsService.getAccountProgress());
    }
}
